package export.monster
{
	import base.BaseMonster;
	
	import com.dusk.util.MathUtil;
	
	import com.dusk.util.RandomUtil;
	
	import com.game.engine.MainGame;
	
	import com.game.manager.AnimationManager;
	import com.greensock.TweenMax;
	
	import export.bullet.EnemyMoveBullet;
	
	import export.bullet.RegionBullet;
	import export.level.StageListener21;
	
	import flash.geom.Rectangle;
	public class Monster207 extends BaseMonster
	{
		//金翅大鹏
		public function Monster207()
		{
			super();
		}
		
		override protected function initAttribute():void
		{
			super.initAttribute();
			mavo.attackRange = 150;
			if(MainGame.getIns().levelData.levelID == "2_3")
			{
				if(gc.pWorld.getBaseLevelListener() as StageListener21 != null)
				{
					if((gc.pWorld.getBaseLevelListener() as StageListener21)["hurtTimes"] > 5)
					{
						mavo.hpMax *= 2;
						setFullHp();
					}
				}
			}
		}
		
		override protected function initBBDC():void
		{
			bbdc = AnimationManager.getAnimation("Monster207Action");
			bbdc.setAction("idle");
			bbdc.turnRight();
			bbdc.addCallBack(onEnterFrame, onActionOver);
			bodyContainer.addChild(bbdc);
		}
		
		override protected function initCollideArea():void
		{
			collideBox = new Rectangle(-35,-103,68,109);
			super.initCollideArea();
		}
		
		override protected function onEnterFrame(action:String, frameCount:int):void
		{
			switch (action)
			{
				case "attack1":
					if(frameCount == 4)
					{
						var b:RegionBullet = new RegionBullet();
						b.setOwner(this);
						b.setDirect(bbdc.getDirect());
						b.setCollideArea(-20,-135,155 * bbdc.getDirect(),135);
						b.setHurt(getActionHurt("attack1"));
						b.setDestroyInCount(8);
						b.setAction("Monster207Attack1");
						gc.gameScene.addChild(b);
						magicBulletArray.push(b);
					}
					break;
				case "skill1":
					//投掷飞矛
					if(frameCount == 13)
					{
						var s1:EnemyMoveBullet = new EnemyMoveBullet("Monster207Skill1");
						s1.setOwner(this);
						s1.setPosition(curAttackTarget.x, -1000);
						s1.setAction("Monster207Skill1");
						s1.setHurt(getActionHurt("skill1"));
						s1.setFuncWhenEnterFrame(skill1Control);
						s1.setFuncWhenHitWall(skill1Explode);
						s1.setSpeed(0,30);
						s1.setSpeedAdd(0,5);
						s1.setDistance(5000);
						gc.gameScene.addChild(s1);
						magicBulletArray.push(s1);
					}
					break;
				case "skill2":
					if(frameCount % 14 == 0)
					{
						createFileBird();
					}
					break;
				case "skill3":
					if(frameCount == 9)
					{
						y -= 350;
						setLostGravity();
						setSteelBody(bbdc.frameLeft);
						faceToTarget();
						var s3:EnemyMoveBullet = new EnemyMoveBullet("Monster207Skill3");
						s3.setOwner(this);
						s3.flipClip();
						s3.setPosition(x, y);
						s3.setDirect(bbdc.getDirect());
						s3.setAction("Monster207Skill3");
						s3.setHurt(getActionHurt("skill3"));
						s3.setSpeed();
						s3.setIsDestroyWhenLastFrame(true);
						gc.gameScene.addChild(s3);
						magicBulletArray.push(s3);
					}
					if(frameCount == bbdc.totalFrame - 1)
					{
						resetGravity();
					}
					break;
				case "skill4":
					setSteelBody(3);
					if(frameCount == 15)
					{
						bbdc.gotoAndPlay(14);
					}
					if(frameCount == 1)
					{
						TweenMax.delayedCall(7,setAction,["relive"]);
					}
					break;
				case "relive":
					if(frameCount == bbdc.frameLeft - 1)
					{
						setFullHp();
					}
			}
		}
		
		override protected function beforeSkill1Start():Boolean
		{
			return hasTarget() && RandomUtil.randBoolean(10);
		}
		
		override protected function beforeSkill2Start():Boolean
		{
			return hasTarget();
		}
		
		override protected function beforeSkill3Start():Boolean
		{
			return hasTarget() && AUtils.GetDisBetweenTwoObj(this, curAttackTarget) < 300;
		}
		
		override protected function beforeSkill4Start():Boolean
		{
			return mavo.getHpPercent() < 25;
		}
		
		private function skill1Control(bu:EnemyMoveBullet):void
		{
			if(bu.getClip().currentFrame == 5)
			{
				bu.getClip().GotoAndPlay(1);
			}
		}
		
		private function skill1Explode(bu:EnemyMoveBullet):void
		{
			if(isReadyToDestroy)
			{
				return;
			}
			var preFrame:int = bu.getClip().currentFrame;
			bu.destroy();
			bu.removeFromParent();
			var s1:EnemyMoveBullet = new EnemyMoveBullet("Monster207Skill1");
			s1.setOwner(this);
			s1.setPosition(bu.x, bu.y);
			s1.setAction("Monster207Skill1");
			s1.setHurt(getActionHurt("skill1"));
			s1.setIsDestroyWhenLastFrame();
			s1.setSpeed();
			s1.getClip().GotoAndPlay(preFrame);
			gc.gameScene.addChild(s1);
			magicBulletArray.push(s1);
		}
		
		private function createFileBird():void
		{
			if(!hasTarget() || curAttackTarget.isReadyToDestroy)
			{
				return;
			}
			var b:EnemyMoveBullet = new EnemyMoveBullet("Monster207Skill2");
			b.setOwner(this);
			b.setAction("Monster207Skill2");
			b.setHurt(getActionHurt("skill2"));
			var angle:Number = RandomUtil.randNum(0, 360);
			const r:Number = 500;
			const a:Number = 4;
			b.rotation = angle;
			b.setPosition(curAttackTarget.x + r * Math.cos(MathUtil.degreeToRadian(angle)), curAttackTarget.y + r * Math.sin(MathUtil.degreeToRadian(angle)));
			b.setSpeedAdd(-a * Math.cos(MathUtil.degreeToRadian(angle)), -a * Math.sin(MathUtil.degreeToRadian(angle)));
			b.setIsDestroyWhenLastFrame(true);
			gc.gameScene.addChild(b);
			magicBulletArray.push(b);
		}
	}
}